package com.zx.tradeclient.ctrl.index3;

import java.util.HashMap;
import java.util.Map;

import org.json.JSONException;
import org.json.JSONObject;

import android.app.ProgressDialog;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
import android.widget.Toast;

import com.zx.base.ctrl.BaseActivity;
import com.zx.base.http.HttpUtils;
import com.zx.base.http.HttpUtils.CallBack;
import com.zx.base.util.ActivityTaskManager;
import com.zx.tradeclient.R;

public class SummaryActivity extends BaseActivity implements OnClickListener {

	private TextView company_detail_txt;
	private ProgressDialog progressDialog;
	private String mCompanyID = "";

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.company_summary);

		if (!(ActivityTaskManager.getInstance().containsName("SummaryActivity"))) {
			ActivityTaskManager.getInstance().putActivity("SummaryActivity", this);
		}

		init();

	}

	private void init() {

		setHeader(0);

		mCompanyID = getIntent().getStringExtra("companyID");

		company_detail_txt = (TextView) findViewById(R.id.company_detail_txt);
		
		progressDialog = ProgressDialog.show(SummaryActivity.this, null, "正在获取数据，请稍后.....", true, true);
		getCompanyInfo();

	}

	public void onClick(View v) {
		// TODO Auto-generated method stub
		if (v == header_left) {
			goback();
		} else if (v == header_right) {

		}

	}

	private void getCompanyInfo() {

		Map<String, String> map = new HashMap<String, String>();
		map.put("act", "companyDetail");
		map.put("id", mCompanyID);
		HttpUtils.post(map, new CallBack() {

			@Override
			public void onSuccess(JSONObject response) {
				parseJson(response);
			}

			@Override
			public void onFailure(Throwable e) {
				progressDialog.dismiss();
				Toast toast2 = Toast.makeText(SummaryActivity.this, "错误", Toast.LENGTH_SHORT);
				toast2.setGravity(Gravity.CENTER, 0, 0);
				toast2.show();

			}
		});
	}

	private void parseJson(JSONObject response) {
		try {
			String succeed = response.getString("succeed");

			if (succeed.equals("000")) {

				company_detail_txt.setText(response.getString("companyIntro"));

			} else {
				Toast toast2 = Toast.makeText(SummaryActivity.this, "无数据", Toast.LENGTH_SHORT);
				toast2.setGravity(Gravity.CENTER, 0, 0);
				toast2.show();
			}

			progressDialog.dismiss();

		} catch (JSONException e) {
			progressDialog.dismiss();
			e.printStackTrace();
		}
	}

}